package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 集智（场上每存在1个（己方/敌方/双方）单位，对目标X属性附加X%的加成）
 * @date 2022/2/25 12:00
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.集智)
public class Affix72CollectWisdom extends Buff {

    public Affix72CollectWisdom(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getBaseNumber() {return getParam(0);}
    private int getCamps() {return getParam(1);}
    private PropertyType getAttribute() {return PropertyType.forNumber(getParam(2));}
    private int getAddPer() {return getParam(3);}

    /**
     * 获取双方活人数量
     * @param source
     * @param target
     * @param camps 0己方，1对方，2双方
     * @return
     */
    private int getLiveNumber(Fighter source, Fighter target, int camps) {
        if(camps == CAMPS_SELF){
            return source.getTeam().get活人().size();
        }else if(camps == CAMPS_OPPONENT){
            return target.getTeam().get活人().size();
        }else if(camps == CAMPS_BOTH){
            return source.getTeam().get活人().size()+target.getTeam().get活人().size();
        }else{
            return 0;
        }
    }

    @Override
    public boolean exec(Fighter source, Fighter target) {
        int number = getLiveNumber(source, target, getCamps());
        int times = number / getBaseNumber();

        PropertyType type = getAttribute();
        PropertyData propertyData = new PropertyData();
        boolean set = false;
        long value = 0;
        if (type != null && getAddPer() > 0) {
            value = target.getData().getPropertyData().getValue(type) * getAddPer() * times / VALUE_比率分母;
            propertyData.setValue(type, value);
        }
        if (set) {
            setPropertyData(propertyData);
        }

        Battle.battleLogger(6, "集智：施法者：" + source.getName() + "目标：" + target.getName() + "属性：" + type + "times：" + times + "value" + value);

        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.增益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.collectWisdomState;
    }

}
